package cn.edu.scau.cmi.wusonglang.GUIController;

import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.wusonglang.composite.safe.China;
import cn.edu.scau.cmi.wusonglang.composite.safe.Composite;
import cn.edu.scau.cmi.wusonglang.composite.safe.Japan;
import cn.edu.scau.cmi.wusonglang.composite.safe.Nation;
import cn.edu.scau.cmi.wusonglang.composite.safe.USA;
import cn.edu.scau.cmi.wusonglang.composite.safe.UnitedNations;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextArea;

public class ConsistentGUIController implements Initializable{

	@FXML
	private Button button;
	
	@FXML
	private Button addCountry;
	
	@FXML
	private ChoiceBox choiceBox;
	
	@FXML
	private TextArea textArea;

	private String[] choiceString = {"China","USA","Japan","UnitedNations"};
	
	private String choice = null;
	
	private Nation country = null;
	
	private Composite composite = new Composite();
	
	@Override
	public void initialize(URL location, ResourceBundle resources) {
		
		
		choiceBox.setItems(FXCollections.observableArrayList("China","USA","Japan","UnitedNations"));
		choiceBox.getSelectionModel().selectedIndexProperty().addListener((obserVable,oldValue,newValue)->{
			choice = choiceString[newValue.intValue()];
			
		});
		
	}
	
	public void addCountry() {
		if(choice!=null) {
			if(choice.equals("China")) 
				composite.add(new China());
			
			if(choice.equals("USA"))  
				composite.add(new USA());
			
			if(choice.equals("Japan")) 
				composite.add( new Japan());
		}
	}
	
	public void sayHallo() {
		textArea.clear();
		if(choice!=null) {
			if(choice.equals("China")) 
				country = new China();
			
			if(choice.equals("USA")) 
				country = new USA();
			
			if(choice.equals("Japan")) 
				country = new Japan();
			
			if(choice.equals("UnitedNations"))
				country = composite;
			
		}
		
		textArea.setText(country.sayHallo());
	}
}
